package com.company.thread;

/**
 * @description: some desc
 * @author: ruoan
 * @date: 2020/10/21 17:15
 */
public class MyThread {


    final static Object person = new Object();
    public static class T1 extends Thread{
        @Override
        public void run() {
            synchronized (person) {
                System.out.println(System.currentTimeMillis()+"T1 come");
                try{
                    System.out.println(System.currentTimeMillis()+"T1 wait");
                    person.notify();
                    person.wait();
                }catch (InterruptedException r){
                    r.getStackTrace();
                }
                System.out.println(System.currentTimeMillis()+"T1 over");
            }
        }
    }



    public static class T2 extends Thread{
        @Override
        public void run() {
            synchronized (person) {
                System.out.println(System.currentTimeMillis()+"T2 come");
                try{
                    System.out.println(System.currentTimeMillis()+"T2 wait");
                    person.notify();
                    person.wait();
                }catch (InterruptedException r){
                    r.getStackTrace();
                }
                System.out.println(System.currentTimeMillis()+"T2 over");
            }
        }
    }


    public static void main(String args[]){
        try{
            Thread thread1=new T1();
            Thread thread2=new T2();
            thread1.start();
            thread2.start();
        }catch (Exception e){
            e.printStackTrace();
        }

    }



}
